package com.data.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.data.entity.Role;
import com.data.entity.RoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by rize on 2019/7/8.
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select("SELECT * FROM t_role " +
            "where id = #{id}")
    Role get(Long id);

    @Select("SELECT * FROM t_role")
    List<Role> selectRoleList();

    @Select("SELECT count(1) FROM t_role")
    long selectRoleCount();

    /**
     * 根据角色id查询菜单关联信息
     * @param roleId
     * @return
     */
    @Select("select id,role_id roleId,menu_id menuId  from t_role_menu where role_id=#{roleId}")
    List<RoleMenu> roleMenus(Long roleId);

    /**
     * 根据角色id删除角色菜单关联信息
     * @param roleId
     */
    @Delete("delete from  t_role_menu where role_id=#{roleId}")
    void delRelMenuRoleByRoleId(Long roleId);
}
